<?php

// +----------------------------------------------------------------------
// | 店铺处理
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\event\store;

use app\common\event\Base;
use app\model\store\Store as StoreModel;
use app\model\pos\PosTrade as PosTradeModel;
use think\facade\Url;

class Store extends Base
{


    /**
     * 更新交易
     * @return mixed
     */
    public static function transInfo()
    {
        try {
            $stores = StoreModel::where('status', 1)->where('trade_month', '<>', 0)
                ->whereTime('update_time', '<', date('Y-m-01 00:00:00', time()))
                ->select();
            foreach ($stores as $index => $store) {
                $store['trade_month'] = PosTradeModel::where('merch_no', $store['store_sn'])
                    ->whereTime('trans_time', 'month')->sum('amount');
                $store->save();
            }
            $data['code'] = 0;
            $data['data'] = 'ok';
        } catch (\Exception $e) {
            $data['code'] = 1;
            $data['message'] = $e->getMessage();
        }
        return $data;
    }


}
